package com.cloud.media.api.web;

import com.cloud.media.api.entity.Media;
import com.cloud.media.api.service.MediaService;
import com.cloud.media.common.consts.MediaConsts;
import com.cloud.media.common.result.ByteFile;
import com.cloud.media.interfaces.FeignClientSystem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @program: quokka-server
 * @description: ${description}
 * @author: sl
 * @create: 2019-08-12 15:51
 **/
@RestController
@RequestMapping("media/interface/")
public class MediaInterfaceController {

    @Autowired
    private MediaService mediaService;

    @Autowired
    private FeignClientSystem feignClientSystem;
    @RequestMapping("getAllMediaByIds")
    public List<Media> getAllMediaByIds(@RequestBody List<String> ids) {
        return mediaService.getAllMediaByIds(ids);
    }


    @PostMapping("/autoupload")
    public Media autoUpload(@RequestBody ByteFile file) {
        String mediaRootPath = feignClientSystem.getMediaRootPath(MediaConsts.DEFAULT_MEDIA_ROOT_PATH_CONFIG,
                MediaConsts.DEFAULT_MEIDA_ROOT);
        return mediaService.autoUpload(file.getList().get(0), mediaRootPath,null);
    }
}
